#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    int edgeScore(vector<int>& edges) {
        int n = edges.size();
        vector<long long> count(n);
        int max = 0;
        for (int i = 0; i < n; i++)
        {
            count[edges[i]] += i;
        }
        for (int i = 0; i < n; i++)
        {
            if (count[i] > count[max]) max = i;
        }
        return max;
    }
};